package com.lvan.interceptor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lvan.bean.BaseException;
import com.lvan.constant.Unlogin;
import com.lvan.service.interfaze.IService;

public class LoginAnnotationInterceptor extends HandlerInterceptorAdapter{
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		HandlerMethod handler2 = (HandlerMethod) handler;
		Unlogin login = handler2.getMethodAnnotation(Unlogin.class);
		if(login==null) {
			HttpSession session = request.getSession();
			if(session.getAttribute("user")==null) {
				throw new BaseException("未登陆",IService.UNLOGIN,"您还未登录,请先登录!");
			}
		}
		return super.preHandle(request, response, handler);
	}
}
